package com.vending.controller;

import com.vending.common.response.Result;
import com.vending.model.entity.VendingMachine;
import com.vending.service.VendingMachineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "售货机管理")
@RestController
@RequestMapping("/api/machines")
public class VendingMachineController {
    
    @Autowired
    private VendingMachineService machineService;

    @ApiOperation("获取售货机列表")
    @GetMapping
    public Result<List<VendingMachine>> list(VendingMachine machine) {
        return Result.success(machineService.list(machine));
    }

    @ApiOperation("获取售货机详情")
    @GetMapping("/{id}")
    public Result<VendingMachine> getById(@PathVariable Long id) {
        return Result.success(machineService.getById(id));
    }

    @ApiOperation("添加售货机")
    @PostMapping
    public Result<Void> add(@RequestBody VendingMachine machine) {
        machineService.add(machine);
        return Result.success(null);
    }

    @ApiOperation("更新售货机")
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Long id, @RequestBody VendingMachine machine) {
        machine.setId(id);
        machineService.update(machine);
        return Result.success(null);
    }

    @ApiOperation("删除售货机")
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        machineService.delete(id);
        return Result.success(null);
    }

    @ApiOperation("更新售货机状态")
    @PutMapping("/{id}/status")
    public Result<Void> updateStatus(@PathVariable Long id, @RequestParam String status) {
        machineService.updateStatus(id, status);
        return Result.success(null);
    }
} 